package com.sunagy.demand.front;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * desc：Swagger Restful 文档生成工具配置文件
 * author：三餘無夢生
 * date：2018/4/11
 * time：下午4:01
 */
@EnableSwagger2
@Configuration
public class Swagger2Config {
    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.sunagy.demand.front.controller"))
                .paths(PathSelectors.any())
                .build();
    }

    /**
     * desc：构建 api文档的详细信息函数
     */
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("MASTER  AVAILABILITY ZONE DEMAND RESTFUL API")
                .termsOfServiceUrl("http://localhost/")
                .contact("三餘無夢生")
                .version("1.0")
                .description("API 描述")
                .build();
    }
}